/*
 * Copyright (c) 2015 Uwantsoft Ltd.
 * www.uwantsoft.com
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * Uwantsoft ("Confidential Information").
 * You shall not disclose such Confidential Information and shall use
 * it only in accordance with the terms of the license agreement you
 * entered into with Uwantsoft.
 */

package com.uwantsoft.business.service;

import com.uwantsoft.business.facade.dto.user.UserOverviewQueryCondition;
import com.uwantsoft.business.service.domain.user.User;
import com.uwantsoft.business.service.infrastructure.UserRepository;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author Chuanbao
 */
@Service(value = "userService")
public class UserServiceImpl {

    @Resource(name = "hibernateUserRepository")
    private UserRepository userRepository;

    public User loadUserByUsername(String username) throws UsernameNotFoundException {
        return userRepository.findByUsername(username);
    }

    public void createUser(User user) {
        userRepository.save(user);
    }

    public User obtainUser(String guid) {
        return userRepository.findUser(guid);
    }

    public void updateUser(User user) {
        userRepository.update(user);
    }

    public List<User> obtainUsers(final UserOverviewQueryCondition userOverviewQueryCondition) {
        return userRepository.findUsers(userOverviewQueryCondition);
    }
    public int obtainUsersAmount(final UserOverviewQueryCondition userOverviewQueryCondition){
        return userRepository.findUserTotalAmount(userOverviewQueryCondition);
    }

}
